package com.ruoyi.web.controller.warning;

import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.warning.domain.entity.Service;
import com.ruoyi.warning.domain.query.ServiceQuery;
import com.ruoyi.warning.service.IServicesService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author chenhc
 * @since 2025-03-26
 */
@RestController
@RequestMapping("/services")
@Api(tags = "服务", description = "用于处理服务相关操作的控制器")
public class ServicesController {
    @Resource
    private IServicesService servicesService;
    @ApiOperation("获取所有服务")
    @GetMapping(value = "/getAllServices")
    public R getAllServices(ServiceQuery query)
    {
        return R.ok(servicesService.getAllServices(query));
    }

    @ApiOperation("获取服务的详细信息")
    @GetMapping(value = "/getServiceDetail/{id}")
    public R getServiceDetail(@PathVariable String id) throws Exception
    {
        return R.ok(servicesService.getServiceDetail(id));
    }

    @ApiOperation("新增或修改")
    @PostMapping(value = "/saveOrUpdate")
    public R saveOrUpdate(@RequestBody Service service)
    {
        return R.ok(servicesService.saveOrUpdate(service));
    }
    @ApiOperation("删除")
    @GetMapping(value = "/delete/{id}")
    public R delete(@PathVariable String id)
    {
        return R.ok(servicesService.removeById(id));
    }

    @ApiOperation("修改监控状态")
    //@PreAuthorize("@ss.hasPermi('system:config:export')")
    @GetMapping(value = "/updateDisable/{id}")
    public R<TableDataInfo> updateDisable(@PathVariable String id)
    {
        Service service = servicesService.getById(id);
        service.setServiceDisabled(!service.getServiceDisabled());
        servicesService.updateById(service);
        return R.ok();
    }
}
